
function isValid(s: string): boolean {
    var chars = new Array<string>()
    var head: string = null
    for(var c of s) {
        switch (c) {
            case "(":
            case "{":
            case "[":
                chars.push(c);
                break;
            case ")":
                head = chars.pop()
                if (head !== "(") return false;
                break;
            case "}":
                head = chars.pop()
                if (head !== "{") return false;
                break;
            case "]":
                head = chars.pop()
                if (head !== "[") return false;
                break;
            default: 
                break;
        }
    }
    return chars.length === 0;
};

console.assert( isValid("()"))
console.assert( isValid("()[]{}"))

console.assert( !isValid("(]"))
console.assert( !isValid("([)]"))

console.assert( !isValid("["))
